﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;

namespace HRLib
{
    public class EntityFactory
    {
        [ThreadStatic]
        private static EntityFactory instance;
        public  HrContext Context {get; set;}

        public static EntityFactory Instance
        {
            get
            {
                if (instance == null)
                    instance = new EntityFactory();
                return instance;
            }
        }

        private EntityFactory() { }

        public IEnumerable<Company> GetAllCompanies()
        {
            return Context.Companies.OrderBy(c=>c.Name);
        }

        public IEnumerable<Employee> GetAllEmployees()
        {
            return Context.Employees;
        }

        public Company GetCompany(string taxid)
        {
            return Context.Companies.Single(c => c.TaxId == taxid);
        }
        public Employee GetEmployee(string taxid)
        {
            return Context.Employees.Single(e => e.TaxId == taxid);
        }

        public IEnumerable<Employee> GetEmployeesMakingMoreThan(float salary)
        {
            //LINQ query!
            var q = from emp in Context.Employees
                    where emp.Salary > salary
                    orderby emp.Salary
                    select emp;

            return q.ToList();
        }


    }
}
